home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Inside Mac Games Volume 5 #3
/
IMG 46 Vol 5-3.iso
/
More Goodies
/
More For Your Game
/
Realmz
/
Character Master Source
/
Nemesis Framework
/
Sources
/
nemesis resources.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-03
|
4KB
|
152 lines
//••••••••••••••••••••••••••••••••••••••••••••••
// Some resource related functions
//••••••••••••••••••••••••••••••••••••••••••••••
extern nemesisGlobalPtr G;
OSErr NemesisGetPixPat( int theID, PixPatHandle &thePattern )
{
OSErr error = noErr;
// Assume failure
thePattern = nil;
thePattern = GetPixPat( theID );
if( !thePattern ) // if nil handle
error = resNotFound;
return error;
}
void NemesisDisposePixPat( PixPatHandle &thePattern )
{
if( thePattern ) // Make sure its not nil
{
DisposePixPat( thePattern );
}
}
OSErr NemesisPenPixPat( PixPatHandle &thePattern )
{
OSErr error = noErr;
if( thePattern ) // Check it exists
{
PenPixPat( thePattern );
}
else
error = kNilHandleError;
return error;
}
Handle NemesisGet1Resource( short fileID, OSType resType, short resID )
{
Handle resource = nil;
short saveResFile;
OSErr error;
// save the current resource file and use the one we want
saveResFile = CurResFile();
UseResFile( fileID );
error = ResError();
if (error)
{
UseResFile( saveResFile );
return resource; // set to nil already
}
// try to get handle to resource from our file only
resource = Get1Resource( resType, resID );
/*
Important Note! Some Resource Manager calls -- like Get1Resource()
will return a nil handle when they fail, but ResError() returns
no error! You should look for BOTH an error and a nil handle. Never
trust one or the other alone.
*/
error = ResError(); // look for Resource Manager error
if ( error || resource == nil )
{
resource = nil; // make sure it is nil
}
// restore original resource file
UseResFile(saveResFile);
return(resource);
}
OSErr NemesisGetDialog( short resID, void *dStorage, WindowRef inFront, DialogRef &theDialog)
{
OSErr error = noErr;
DialogTHndl dlog = nil;
Handle ditl = nil;
// assume failure right off
theDialog = nil;
// preflight all dialog requests */
error = NemesisCheckMemory( kDialogMemory );
if (error)
{
return error;
}
// are resources actually present?
/*
If they are not present and we call GetNewDialog(), the Mac crashes!
This might happen if some wise guy renumbered resources while
playing with ResEdit, or we forgot to create them. This approach
helps make your code as bullet proof as possible. Never assume anything!
*/
dlog = (DialogTHndl)NemesisGet1Resource( G->DefaultResFile(), 'DLOG', resID );
if ( !dlog )
{
error = resNotFound;
return error;
}
HNoPurge ( (Handle) dlog ); // don't want to lose it
ditl = NemesisGet1Resource( G->DefaultResFile(), 'DITL', (**dlog).itemsID);
if (!ditl)
{
HPurge ( (Handle)dlog );
error = resNotFound;
return error;
}
HNoPurge ((Handle) ditl); // don't want to lose it
// we're safe, get the dialog ( required resources already in memory )
theDialog = GetNewDialog( resID, dStorage, inFront );
// always check for a nil pointer or a memory error
if ( !theDialog || MemError() )
{
HPurge ((Handle)dlog); // clean up the other stuff
HPurge ((Handle)ditl);
if (theDialog)
{
DisposeDialog( theDialog );
theDialog = nil; // just to be sure
}
error = memFullErr;
}
return(error);
}
void NemesisGetIndString( short resID, short index, Str255 myString )
{
int saveResFile;
// save the current resource file and use the default
saveResFile = CurResFile();
UseResFile( G->DefaultResFile() );
myString[0] = 0; // make sure it's empty to start, in case this fails
GetIndString(myString, resID, index);
// restore original resource file
UseResFile( saveResFile );
}